package com.wc.算法提高课.D第四章_高级数据结构.并查集.搭配购买;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.util.StringTokenizer;

/**
 * @Author congge
 * @Date 2024/5/15 17:34
 * @description https://www.acwing.com/problem/content/1254/
 */
public class Main {
    /**
     * 思路：并查集存集合，计算用01背包, 用根存一下价值和重量
     */
    static FastReader sc = new FastReader();
    static PrintWriter out = new PrintWriter(System.out);
    static int N = 10010;
    static int[] p = new int[N], w = new int[N], v = new int[N];
    static int[] f = new int[N];
    static int n, m, W;

    public static void main(String[] args) {
        n = sc.nextInt();
        m = sc.nextInt();
        W = sc.nextInt();
        for (int i = 1; i <= n; i++) p[i] = i;
        for (int i = 1; i <= n; i++) {
            w[i] = sc.nextInt();
            v[i] = sc.nextInt();
        }
        while (m-- > 0) {
            int a = sc.nextInt(), b = sc.nextInt();
            a = find(a);
            b = find(b);
            if (a != b) {
                w[b] += w[a];
                v[b] += v[a];
                p[a] = b;
            }
        }
        for (int i = 1; i <= n; i++) {
            if (p[i] == i) {
                for (int j = W; j >= w[i]; j--) {
                    f[j] = Math.max(f[j], f[j - w[i]] + v[i]);
                }
            }
        }
        out.println(f[W]);
        out.flush();
    }

    static int find(int x) {
        if (p[x] != x) p[x] = find(p[x]);
        return p[x];
    }
}

class FastReader {
    StringTokenizer st;
    BufferedReader br;

    FastReader() {
        br = new BufferedReader(new InputStreamReader(System.in));
    }

    String next() {
        while (st == null || !st.hasMoreElements()) {
            try {
                st = new StringTokenizer(br.readLine());
            } catch (IOException e) {
                e.printStackTrace();
            }
        }
        return st.nextToken();
    }

    int nextInt() {
        return Integer.parseInt(next());
    }

    String nextLine() {
        String s = "";
        try {
            s = br.readLine();
        } catch (IOException e) {
            e.printStackTrace();
        }
        return s;
    }

    long nextLong() {
        return Long.parseLong(next());
    }

    double nextDouble() {
        return Double.parseDouble(next());
    }

    // 是否由下一个
    boolean hasNext() {
        while (st == null || !st.hasMoreTokens()) {
            try {
                String line = br.readLine();
                if (line == null)
                    return false;
                st = new StringTokenizer(line);
            } catch (IOException e) {
                throw new RuntimeException(e);
            }
        }
        return true;
    }
}